<template>
  <div>
    <!--面包屑导航区域-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!--卡片视图-->
    <el-card>
      <!--表格-->
      <el-table
        :data=" result.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
        border
        style="width: 100%"
        stripe
        height="620px"
      >
        <el-table-column type="index"> </el-table-column>
        <el-table-column prop="authName" label="权限名称"> </el-table-column>
        <el-table-column prop="path" label="路径"> </el-table-column>
        <el-table-column prop="level" label="权限等级">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.level == 0">一级</el-tag>
            <el-tag type="success" v-if="scope.row.level == 1">二级</el-tag>
            <el-tag type="warning" v-if="scope.row.level == 2">三级</el-tag>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      rightsList: [], //所有权限列表
      result: [],
      total: 0,
      currentPage: 1,
      pageSize: 10
    }
  },
  created() {
    this.getRightsList()
  },
  methods: {
    async getRightsList() {
      //获取权限列表
      let result = await new this.Request(
        this.Urls.m().getRights + '/list'
      ).modeGet()
      console.log('权限列表', result)
      if (result.meta.status !== 200) {
        return this.$message.error(result.meta.msg)
      } else {
        this.rightsList = result.data
        this.total=result.data.length;
        this.currentChangePage(this.rightsList, this.currentPage)
      }
    },
    handleSizeChange: function(pageSize) {
      // 每页条数切换
      this.pageSize = pageSize
      this.handleCurrentChange(this.currentPage)
    },
    handleCurrentChange: function(currentPage) {
      //页码切换
      this.currentPage = currentPage
     this.currentChangePage(this.rightsList, currentPage)
    },
    currentChangePage(list, currentPage) {
      let to = currentPage * this.pageSize
      for (let from=0;from< to; from++) {
        if (list[from]) {
          this.result.push(list[from])
        }
      }
    }
  }
}
</script>
<style lang="less" scoped></style>
